const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

exports.main = async (event, context) => {
  try {
    const { page, scene } = event
    const result = await cloud.openapi.wxacode.getUnlimited({
      page,
      scene,
      checkPath: true,
      envVersion: 'release'
    })
    
    // 上传二维码到云存储
    const upload = await cloud.uploadFile({
      cloudPath: `qrcode/${Date.now()}.jpg`,
      fileContent: result.buffer
    })
    
    return {
      success: true,
      fileID: upload.fileID
    }
  } catch (err) {
    console.error(err)
    return {
      success: false,
      error: err
    }
  }
} 